<template>
  <!-- 底部部分 -->
  <footer class="footer">
    <span class="todo-count"
      ><strong>{{ leftCount }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          @click.prevent="$emit('changeType', 'all')"
          href="#/"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'active' }"
          @click.prevent="$emit('changeType', 'active')"
          href="#/active"
          >进行中</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'completed' }"
          @click.prevent="$emit('changeType', 'completed')"
          href="#/completed"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clear">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
    },
    type: String,
  },
  methods:{
    clear(){
      this.$emit('clearAll')
    }
  },
  computed: {
    leftCount() {
      return this.list.reduce((sum, item) => {
        if (!item.isDone) return sum + 1
        return sum
      }, 0)
    },
  },
}
</script>

<style></style>
